<%--
  Created by IntelliJ IDEA.
  User: liuqing
  Date: 2024/11/22
  Time: 12:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="admin_header.jsp"%>
<%@ include file="admin_sidebar.jsp"%>

<div class="content">
    <div style="margin-top: 10px;font-weight: 600;">首页/用户记录(总共 ${userCount} 条)</div>
    <form action="AdminUserSearchServlet" method="post" class="navbar-form navbar-left" role="search" style="padding: 0;margin-bottom: 0">
        <div class="form-group">
            <input type="text" class="form-control" name="keyword" placeholder="用户名或者邮箱" style="width: 500px">
        </div>
        <button type="submit" class="btn btn-default">Search</button>
        <button type="button" class="button-1"><a href="admin_UserAdd.jsp">添加用户</a></button>
    </form>
    <div class="table-container">
        <table class="table"> <!-- 注意这里的类名是 "table" 而不是 "table-container" -->
            <thead>
            <tr>
                <th>NO</th>
                <th>User_ID</th>
                <th>用户名</th>
                <th>密码</th>
                <th>邮箱</th>
                <th>身份</th>
                <th>创建时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <!-- 使用JSP的c:forEach循环来动态生成表格行 -->
            <c:forEach var="user" items="${userList}" varStatus="status">
                <tr>
                    <!-- 使用 varStatus.index 来获取当前行的索引（从0开始） -->
                    <!-- 使用 varStatus.count 来获取当前行的计数（从1开始） -->
                    <td>${(userPage-1) * 10 + status.count}</td>
                    <td>${user.user_id}</td>
                    <td>${user.username}</td>
                    <td>${user.password}</td>
                    <td>${user.email}</td>
                    <td><c:if test="${user.isAdmin == true}">管理员</c:if>
                        <c:if test="${user.isAdmin == false}">用户</c:if></td>
                    <td>${user.created_time}</td>
                    <td>
                        <button class="button-update"><a href="AdminUserHelpServlet?user_id=${user.user_id}&page=${userPage}"><i class="fa-solid fa-pen-to-square" style="color: white"></i></a></button>
                        <button class="button-delete"><a href="AdminUserDeleteServlet?user_id=${user.user_id}&page=${userPage}"><i class="fa-solid fa-trash" style="color: white"></i></a></button>
                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
    </div>
    <div class="page-information">
        <nav aria-label="Page navigation">
            <ul class="pagination" style="margin: 0">
                <li>
                    <c:if test="${userPage > 1}">
                        <a href="UserPageServlet?page=${userPage-1}" aria-label="Previous">
                            <span aria-hidden="true">&laquo;</span>
                        </a>
                    </c:if>
                </li>
                <c:forEach var="pageNum" begin="1" end="${userPageCount}">
                    <li><a href="UserPageServlet?page=${pageNum}" class="page-link">${pageNum}</a></li>
                </c:forEach>
                <li>
                    <c:if test="${userPage < userPageCount}">
                        <a href="UserPageServlet?page=${userPage + 1}" aria-label="Next">
                            <span aria-hidden="true">&raquo;</span>
                        </a>
                    </c:if>
                </li>
            </ul>
        </nav>
    </div>
    <input type="hidden" value="${userPage}" id="currentPage">
</div>

<%@ include file="admin_footer.jsp"%>